home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / lib / tcl / mxedit.command < prev    next >
Encoding:
Text File  |  1992-07-16  |  3.9 KB  |  146 lines

  1. #
  2. # mxedit.command --
  3. #    Definitions for the command entry
  4. #
  5. # Copyright (c) 1992 Xerox Corporation.
  6. # Use and copying of this software and preparation of derivative works based
  7. # upon this software are permitted. Any distribution of this software or
  8. # derivative works must comply with all applicable United States export
  9. # control laws. This software is made available AS IS, and Xerox Corporation
  10. # makes no warranty about the software, its performance or its conformity to
  11. # any specification.
  12.  
  13. # Imported globals
  14. # mxFeedback - the command entry gets packed before the feedback entry
  15. #    so we import the name of the feedback widget to achieve this
  16.  
  17. # Exported globals
  18. # focus - ordinarily the focus is shifted back to the main editing
  19. #    window after a command, but this variable lets commands change
  20. #    that default behavior by setting focus to the name of another widget
  21.  
  22. # File globals
  23. # command - the name of the command entry
  24. # commandState - whether or not the command entry is visible
  25. # commandMenu - the menu that controls the command entry's visibility
  26.  
  27. # mxCommandEntry --
  28. # An entry widget for entering commands
  29.  
  30. proc mxCommandEntry { parent { width 20 } { where {bottom fillx expand} } } {
  31.     global command commandState
  32.     if [catch {labeledEntry $parent .command Command: $width $where} msg] {
  33.     mxFeedback "labeledEntry failed $msg"
  34.     return
  35.     } else {
  36.     set self $msg
  37.     mxCommandBindings $self.entry
  38.     }
  39.     # labeldEntry packs us so the command window is visible
  40.     set commandState commandVisible
  41.     set command $self
  42.     return $self
  43. }
  44.  
  45. # mxCommandFocus
  46. #    Focus on the command window, making it visible if needed
  47.  
  48. proc mxCommandFocus { } {
  49.     global command commandState
  50.     case $commandState in {
  51.     commandVisible { }
  52.     commandHidden { mxCommandShow }
  53.     }
  54.     focus $command.entry
  55. }
  56.  
  57. # mxCommandMenuEntry --
  58. #    Set up the menu entry that controls the display of the command window
  59. #    We'll remember the name of the menu so we can adjust the
  60. #    menu entry to reflect the current state
  61.  
  62. proc mxCommandMenuEntry { menuName } {
  63.     global commandState commandMenu
  64.  
  65.     set commandMenu ${menuName}
  66.  
  67.     case $commandState in {
  68.     "commandVisible" {
  69.         mxMenuAdd $menuName "Hide command window" {mxCommandHide}
  70.     }
  71.     "commandHidden" {
  72.         mxMenuAdd $menuName "Open command window" {mxCommandShow}
  73.     }
  74.     }
  75. }
  76. # mxCommandHide --
  77. #    Unpack the command window to save screen space
  78.  
  79. proc mxCommandHide { } {
  80.     global command commandState commandMenu
  81.  
  82.     set commandState commandHidden
  83.     pack unpack $command
  84.     mxMenuEntryConfigure $commandMenu "Hide command window" \
  85.         -command { mxCommandShow } -label "Open command window"
  86. }
  87.  
  88. # mxCommandShow --
  89. #    Pack the command window so it shows up
  90.  
  91. proc mxCommandShow { } {
  92.     global command commandState commandMenu
  93.     global mxFeedback
  94.  
  95.     set commandState commandVisible
  96.     pack before $mxFeedback $command {bottom fillx frame s}
  97.  
  98.     mxMenuEntryConfigure $commandMenu "Open command window" \
  99.         -command { mxCommandHide } -label "Hide command window"
  100. }
  101.  
  102. # A flag to control if focus is returned to the editing window after a command
  103. global focus
  104. set focus default
  105.  
  106. # mxDoCmd --
  107. #    Execute the commands issued to the command entry
  108. #    This is ordinarily bound to hitting <Return> in the command entry
  109.  
  110. proc mxDoCmd { } {
  111.     global focus
  112.     global command
  113.  
  114.     set cmd [$command.entry get]
  115.     if {[llength $cmd] != 0} {
  116.     case [lindex $cmd 0] in {
  117.         {echo feedback mxFeedback} {
  118.         # Echo inputs
  119.         mxFeedback "$cmd"
  120.         } help {
  121.         # Display help information
  122.         mxopen [info library]/mxedit.tutorial
  123.         } default {
  124.         # Pass on the command to Tcl
  125.         if [catch {uplevel #0 $cmd} msg] {
  126.             mxFeedback "Cmd failed: $msg"
  127.         } else {
  128.             if {[string compare "$msg" ""] != 0} {
  129.             mxFeedback $msg
  130.             } else {
  131.             mxFeedback "ok"
  132.             }
  133.         }
  134.         }
  135.     }
  136.     }
  137.     # Let a command do its own focus if it wants,
  138.     # otherwise return the focus to the editting window
  139.     if {[string compare $focus "default"] == 0} {
  140.     mxeditFocus
  141.     }
  142.     set focus default
  143. }
  144.  
  145.  
  146.